<template>
  <div></div>
</template>
<script setup name="callback">
import router from "@/router";
import { hisLogin } from "@/api/pub";
import { useRouter } from 'vue-router'
const { proxy } = getCurrentInstance()
const $router = useRouter()
onMounted(() => {
  toLogin();
});

function toLogin() {
  const params = decodeURIComponent(
    window.location.search || window.location.hash
  );
  let code = params ? params.split("?code=")[1] : "";
  console.log(code);
  if (code) {
    proxy.$store
      .dispatch("user/loginbyCode", {api: hisLogin, code: code})
      .then((res) => {
        if (res) {
          $router.push({
            path: res.url || "/"
          });
        }
      })
      .catch(() => {
        router.replace("/login");
      });
  } else {
    router.replace("/login");
  }
}
</script>
